**Author: Abeberese, Barnwal, Chaurey, Mukherjee
**This do-file will generate Figure 2, Table A2 and Table A3
**Date: May 2021

clear
capture log close
set matsize 4000
set scheme s2mono, perm


**Set directories
*Add personal root path for your machine directory

global ROOT "/Users/rchaurey/Dropbox/Indonesia Firms/DataFolderRESTAT/"
global dofiles "${ROOT}/Code"
global data "${ROOT}/Input"
global output "${ROOT}/Output/"




******************************************************************************
**Firm-level regressions
******************************************************************************

use "${data}/mayor_manufactureBaselineRegressions_longrun", clear


**Define years since democratization
*t=0, first year of democratic mayor
gen t = year - mayor_appyr - 5

**Bin endpoints
replace t = -5 if t<=-5
replace t = 5 if t>=5&t~=.
xi i.t, noomit

des _It_*
gen zero = 0

label var _It_1 "[-5]"
label var _It_2 "[-4]"
label var _It_3 "[-3]"
label var _It_4 "[-2]"
label var zero "[-1]"
label var _It_6 "[0]"
label var _It_7 "[1]"
label var _It_8 "[2]"
label var _It_9 "[3]"
label var _It_10 "[4]"
label var _It_11 "[5]"

*Fully dynamic specification
foreach v of varlist  log_labor_productivity ltfpLP   log_v_production  {
est clear
reghdfe `v'  _It_1-_It_4 zero _It_6-_It_11  ,   absorb(idno ind5year)  cluster(district)

estimates store modelLRFull
outreg2 using "${output}`v'_Full.xls", ///
keep(_It* zero)   addtext(firm FE, Yes, 5 digit industry X year FE, Yes) replace

coefplot modelLRFull, vertical ciopts(recast(rcap) lcolor(gs8) lpattern(solid) ) lcolor(black)  recast(connected) keep(_It* zero) omitted levels (90) title (`v') graphregion(color(white)) title("`: var label `v''") ///
xtitle("Years since democratization") bgcolor(white) yline(0, lcolor(gs14) lpattern(solid)) xlabel(, labsize(small)) xline(5, lcolor(gs12))

graph save "${output}`v'_Full", replace
graph export "${output}`v'_Full.png", as(png)  replace

}

***Testing for parallel trends ala Borusyak and Jaravel (2018) 
**Note that, following Borusyak and Jaravel (2018), we have dropped _It_1 (first lag - k1) and _It_5 (one period before democratization - k2)
foreach v of varlist  log_labor_productivity ltfpLP   {
est clear
reghdfe `v'  _It_2-_It_4 zero _It_6-_It_11  ,   absorb(idno ind5year)  cluster(district)
test _It_2 = _It_3 = _It_4 = 0
}

***Conditional on passing the pre-trends F-test -- drop all pre periods and run the event study
foreach v of varlist  log_labor_productivity ltfpLP   log_v_production  {
est clear
reghdfe `v'   zero _It_6-_It_11  ,   absorb(idno ind5year)  cluster(district)
estimates store modelLRSemi
outreg2 using "${output}`v'_Semi.xls", ///
keep(_It* zero)   addtext(firm FE, Yes, 5 digit industry X year FE, Yes) replace

coefplot modelLRSemi, vertical ciopts(recast(rcap)  lcolor(gs8) lpattern(solid) ) lcolor(black)  recast(connected) keep(_It* zero) omitted levels (90) title (`v') graphregion(color(white)) title("`: var label `v''") ///
xtitle("Years since democratization") bgcolor(white) yline(0, lcolor(gs14) lpattern(solid)) xlabel(, labsize(small)) 

graph save "${output}`v'_Semi", replace
graph export "${output}`v'_Semi.png", as(png)  replace

}




